/**
 *!
 * \file        b_hal_adc.h
 * \version     v0.0.1
 * \date        2024/03/21
 * \author      Bean(notrynohigh@outlook.com)
 *******************************************************************************
 * @attention
 *
 * Copyright (c) 2024 Bean
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *******************************************************************************
 */
#ifndef __B_HAL_ADC_H
#define __B_HAL_ADC_H

#ifdef __cplusplus
extern "C" {
#endif

/*Includes ----------------------------------------------*/
#include "b_hal.h"

/**
 * \addtogroup B_HAL
 * \{
 */

/**
 * \addtogroup ADC
 * \{
 */

/**
 * \defgroup ADC_Exported_Types
 * \{
 */

typedef enum
{
    bADC_CHANNEL_0 = 0,
    bADC_CHANNEL_1,
    bADC_CHANNEL_2,
    bADC_CHANNEL_3,
    bADC_CHANNEL_4,
    bADC_CHANNEL_5,
    bADC_CHANNEL_6,
    bADC_CHANNEL_7,
    bADC_CHANNEL_8,
    bADC_CHANNEL_9,
    bADC_CHANNEL_10,
    bADC_CHANNEL_11,
    bADC_CHANNEL_12,
    bADC_CHANNEL_13,
    bADC_CHANNEL_14,
    bADC_CHANNEL_15,
    ADC_CHANNEL_TEMP,    /* Temperature sensor channel */
    ADC_CHANNEL_VREF,    /* Internal reference voltage channel */
    ADC_CHANNEL_VBAT,    /* Battery voltage channel */
} bAdcChannel_t;

typedef enum
{
    ADC_SAMPLETIME_1_5 = 0,    /* 1.5 cycles */
    ADC_SAMPLETIME_7_5,        /* 7.5 cycles */
    ADC_SAMPLETIME_13_5,       /* 13.5 cycles */
    ADC_SAMPLETIME_28_5,       /* 28.5 cycles */
    ADC_SAMPLETIME_41_5,       /* 41.5 cycles */
    ADC_SAMPLETIME_55_5,       /* 55.5 cycles */
    ADC_SAMPLETIME_71_5,       /* 71.5 cycles */
    ADC_SAMPLETIME_239_5,      /* 239.5 cycles */
} bAdcSampleTime_t;

typedef enum
{
    ADC_RESOLUTION_12B = 0,    /* 12-bit resolution */
    ADC_RESOLUTION_10B,        /* 10-bit resolution */
    ADC_RESOLUTION_8B,         /* 8-bit resolution */
    ADC_RESOLUTION_6B,         /* 6-bit resolution */
} bAdcResolution_t;

typedef struct
{
    bAdcChannel_t channel;     /* ADC channel */
    bAdcSampleTime_t sampleTime; /* ADC sample time */
    bAdcResolution_t resolution; /* ADC resolution */
} bAdcConfig_t;

/**
 * \}
 */

/**
 * \defgroup ADC_Exported_Functions
 * \{
 */

int bHalAdcInit(bAdcConfig_t *config);
int bHalAdcDeInit(void);
int bHalAdcStart(void);
int bHalAdcStop(void);
int bHalAdcRead(bAdcChannel_t channel, uint16_t *value);
int bHalAdcReadMulti(bAdcChannel_t *channels, uint16_t *values, uint8_t count);

/**
 * \}
 */

/**
 * \}
 */

/**
 * \}
 */

#ifdef __cplusplus
}
#endif

#endif /* __B_HAL_ADC_H */

/************************ Copyright (c) 2024 Bean *****END OF FILE****/ 